﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using SMBL.Operation;

/// <summary>
///PictureDao 的摘要说明
/// </summary>
public class PictureDao :  IPictureDao
{
	public PictureDao()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    public Picture GetPictureById(string pictureId)
    {
        DataSet ds = SqlOpHelper.Query("niyi", new Object[] { "pictureId" }, new Object[] { pictureId }, "select * from Picture where PictureId = @pictureId");
        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            return Picture.ConvertToPicture(ds.Tables[0].Rows[0]);
        else
            return null;
    }

    public IList<Picture> GetPictureList()
    {
        DataSet ds = SqlOpHelper.Query("niyi", new Object[] { }, new Object[] { }, "select * from Picture");
        if (ds.Tables.Count > 0)
            return Picture.ConvertToPictureList(ds.Tables[0]);
        else
            return null;
    }

    public IList<Picture> GetPictureListByCategory(string category)
    {
        DataSet ds = SqlOpHelper.Query("niyi", new Object[] { "category" }, new Object[] { category }, "select * from Picture where Category=@category");
        if (ds.Tables.Count > 0)
            return Picture.ConvertToPictureList(ds.Tables[0]);
        else
            return null;
    }

    public void DelPicture(string pictureId)
    {
        SqlOpHelper.Execute("niyi", new Object[] { "pictureId" }, new Object[] { pictureId }, "Delete from Picture where PictureId = @pictureId");
    }

    public void AddPicture(Picture picture)
    {
        SqlOpHelper.Execute("niyi", new Object[] { "uploadDate", "category", "imageName" }, new Object[] { picture.UploadDate, picture.Category, picture.ImageName }, "Insert Into Picture (UploadDate, Category,ImageName) Values (@uploadDate, @category,@imageName)");
    }
}
